package org.xg.study.pd.store.impl;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xg.study.pd.goods.DeliverReq;
import org.xg.study.pd.goods.GoodsService;
import org.xg.study.pd.store.ICommodity;

import java.util.Map;


/**
 * @author CMG
 * @version 1.0
 * @cLassName GoodsCommodityService
 * @description 实物商品发放接口
 * @date 2021/9/9 9:57
 **/
public class GoodsCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(GoodsCommodityService.class);

    private GoodsService goodsService = new GoodsService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(uId));
        deliverReq.setUserPhone(queryUserPhone(uId));
        deliverReq.setSku(commodityId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));
        Boolean isSuccess = goodsService.deliverGoods(deliverReq);
        logger.info("请求参数【实物商品】=> uId:{}. commodity:{}, bizId:{}, extMap:{}", uId, commodityId, bizId, JSONObject.toJSON(extMap));
        logger.info("测试结果【实物商品】:{}", isSuccess);

        if (!isSuccess) {
            throw new RuntimeException("实物商品发放失败");
        }
    }

    private String queryUserName(String uId) {
        return "花花";
    }

    private String queryUserPhone(String uId) {
        return "15200101232";
    }
}
